<?php
require_once 'Logger/Event.php';
class Logger_Log {
    
    protected $_name;
    protected $_level;
    protected $_offLog      =   false;
    protected $_appenders   =   array();
    
    public function __construct($name)
    {
        $this->_name    =   $name;
    }
    public function setLevle($level)
    {
        $this->_level   =   $level;
    }
    public function offLog()
    {
        $this->_offLog  =   true;
    }
    public function addAppender(Logger_Appender_Abstraction $appender)
    {
                
        $appendeName   =   $appender->getName();
        
        $this->_appenders[$appendeName] =   $appender;
        
    }
    public function callAppender(Logger_Event $event)
    {
      
        foreach($this->_appenders as $appender)
            $appender->doAppender($event);
    }
    public function info($msg,$param = array())
    {
        $this->recordLog($msg,Logger::INFO,$this->_name, $param);
    }
    public function debug($msg,$param = array())
    {
        $this->recordLog($msg,Logger::DEBUG,$this->_name, $param);
    }
    public function warn($msg,$param = array())
    {
        $this->recordLog($msg,Logger::WARN,$this->_name, $param);
    }
    public function error($msg,$param = array())
    {
        $this->recordLog($msg,Logger::ERROR,$this->_name, $param);
    }
    public function fatal($msg,$param = array())
    {
        $this->recordLog($msg,Logger::FATAl,$this->_name, $param);
    }
    public  function recordLog($message,$level,$name,$param = array())
    {
        
        if($level >= $this->_level)
            $this->callAppender(new Logger_Event($this->_name,$level,$message,time(),$param) );
    }
}

?>